<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
      </el-col>
      <el-col :span="1.5">
         <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="posterList">
      <el-table-column label="序号" align="center" prop="id" width="100" />
      <el-table-column label="标题" align="center" prop="title" :show-overflow-tooltip="true" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
            <el-button
            size="mini"
            type="primary"
            style="width:60px;"
            @click="handleUpdate(scope.row,'preview')"
          >编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            style="width:60px;"
            @click="handleRemove(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { listPoster, addPoster, delPoster } from "@/api/system/poster";
export default {
  name: "Poster",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 总条数
      total: 0,
      posterList: []
    };
  },
  created() {
    this.getWork()
  },
  methods: {
    getWork() {
      let queryParams = {}
      listPoster(queryParams).then(response => {
      console.log('listPoster', response)
        this.posterList = response;
      });
    },
    handleUpdate(row) {
      this.$router.push({path: '/posters/edit', query: {posterId: row.id}})
    },
    handleRemove(row) {
      delPoster(row.id).then(response => {
        console.log('listPoster', response)
        this.$message.success('删除成功')
        this.getWork()
      });
    },
    // /** 搜索按钮操作 */
    handleQuery() {
      this.getWork()
    },
    /** 新增按钮操作 */
    handleAdd() {
      let queryParams = { title: '标题'}
      addPoster(queryParams).then(response => {
        console.log('addPoster', response)
        this.$router.push({path: '/posters/edit', query: {posterId: response.id}})
      });
    },

  }
};
</script>
